package com.wwtech.epp.utils;

import com.amap.api.maps2d.AMapUtils;
import com.amap.api.maps2d.model.LatLng;
import com.socks.library.KLog;
import com.wwtech.epp.entity.sign.Config;

import java.util.List;

/**
 * 作者：Android on 2017/9/28
 * 邮箱：365941593@qq.com
 * 描述：
 */

public class SignUtil {

    //判断是否是在正常的打卡时间
    public static boolean isNormalTime(String beginTime, String endTime, String currentTime) {
        if (getTimeMillins(beginTime) <= getTimeMillins(currentTime) && getTimeMillins(endTime) >= getTimeMillins(currentTime)) {
            return true;
        } else {
            return false;
        }

    }

    //获取00:00格式的时间数，以分钟为单位，从00:00开始
    public static long getTimeMillins(String time) {
        KLog.i(time);
        KLog.i(Long.parseLong(time.substring(0, 2)) * 60 + Long.parseLong(time.substring(3, 5)));
        return Long.parseLong(time.substring(0, 2)) * 60 + Long.parseLong(time.substring(3, 5));

    }

    public static boolean isInSignArea(int distance, List<Config.LocationsBean> locationList, LatLng latLonPoint) {
        for (int i = 0; i < locationList.size(); i++) {
            LatLng currentLatLon = new LatLng(locationList.get(i).getLat(), locationList.get(i).getLng());
            KLog.i(AMapUtils.calculateLineDistance(currentLatLon, latLonPoint));
            if (AMapUtils.calculateLineDistance(currentLatLon, latLonPoint) <= distance) {
                return true;
            }
        }
        return false;
    }
}
